<?php

namespace admin\controllers;

use app\models\ar\UserAr;
use app\models\Project;
use admin\components\BaseAuthController;
use app\models\UserProfile;

class ServiceController extends BaseAuthController{

    public $name = '服务管理';

    public function actionIndex(){
        $params = $this->getParam();
        $params['type'] = Project::TYPE_SERVICE;

        $model = new Project();
        $model->with = ['profile'];

        $wd = $this->get('wd');
        $search_type = intval($this->get('search_type'));
        if ($search_type === 1 && !empty($wd)) {
            $profile = UserProfile::find()->where(['nickname' => $wd])->one();
            $model->where = ['uid' => $profile ? $profile->uid : 0];
        }
        if ($search_type === 2 && !empty($wd)) {
            $userAr = UserAr::find()->where(['phone' => $wd])->one();
            $model->where = ['uid' => $userAr ? $userAr->id : 0];
        }
        if ($search_type === 3 && !empty($wd)) {
            $model->where = ['like', 'title', $wd];
        }

        $dataProvider = $model->search($params);
        return $this->render(compact('dataProvider'));
    }

    public function actionView($id){
        return $this->render(['model' => $this->findModel($id,Project::className())]);
    }
}
